#include <iostream>

using std::cout;
using std::endl;

class Test
{
public:
    Test(int test)
    : _itest(test)
    {   cout << "Test(int)"<< endl;    }

    ~Test() {   cout << "~Test()" << endl;  }

    void print() const 
    {   cout <<"Test::_itest:" << _itest << endl;   }


private:
    int _itest;
};

class Base
{
public:
    //当基类中定义了有参构造函数时，系统就不会再提供默认构造函数
    Base()
    : _base(0)
    , _data(0)
    {   cout << "Base()" << endl;}

    Base(long base, long data)
    : _base(base)
    , _data(data)
    {   
        cout << "Base(long)" << endl;
    }

    ~Base() {   cout << "~Base()" << endl;  }
    
    void print() const
    {   cout << "Base::_base:" << _base << endl;    }

protected:
    long _data;

private:
    long _base;
};

class Derived
: public Base
{
public:
    Derived(long base, int t, long d1, long d2, long derived)
    : _test(t)  
    , Base(base, d1)//基类成员的初始化只能交给基类构造函数来完成
    //, _data(d1)//派生类构造函数的初始化列表中不能初始化基类成员
    , _data(d2) //_data一定是派生类中的成员
    , _derived(derived)
    {   cout << "Derived(long,long)" << endl;}

    ~Derived() {    cout << "~Derived()" << endl;}

    void display() const
    {
        //这里会隐藏基类的同名成员,访问的是派生类的成员
        cout << "_data:" << _data << endl;
        //如果希望访问基类同名成员，只有加上类作用域限定符才可以
        cout << "Base::_data:" << Base::_data << endl;
        cout << "_derived:" << _derived << endl;
    }

private:
    Test _test;
    long _derived;
    long _data;
};

int main()
{
    Derived d1(1, 2, 3, 4, 5);
    d1.print();
    d1.display();

    return 0;
}

